﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Media;

namespace AlarmClock
{
    public class TimeUp
    {
        private static RingType preType = RingType.RING_NULL;
        private static SoundPlayer player;
        public static void Ring(RingType type)
        {
            if (type == RingType.RING_LONG)
            {
                if (player == null)
                {
                    player = new SoundPlayer();
                    player.SoundLocation = "Missing.wav";
                    player.Play();
                }
                else
                {
                    if (player.IsLoadCompleted)
                    {
                        player.SoundLocation = "Missing.wav";
                        player.Play();
                    }
                    else
                    {
                        if (type != preType)
                        {
                            Stop();
                            player = new SoundPlayer();
                            player.SoundLocation = "Missing.wav";
                            player.Play();
                        }
                    }
                }
            }
            else
            {
                if (player == null)
                {
                    player = new SoundPlayer();
                    player.SoundLocation = "Bubble.wav";
                    player.Play();
                }
                else
                {
                    if (player.IsLoadCompleted)
                    {
                        player.SoundLocation = "Bubble.wav";
                        player.Play();
                    }
                    else
                    {
                        if (type == preType)
                        {
                            Stop();
                            player = new SoundPlayer();
                            player.SoundLocation = "Bubble.wav";
                            player.Play();
                        }
                    }
                }
            }
            preType = type;
        }
        public static void Stop()
        {
            try
            {
                if (player != null)
                {
                    if (player.IsLoadCompleted)
                    {
                        player.Stop();
                        player = null;
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
            }
        }
    }
    public enum RingType
    {
        RING_LONG, RING_SHORT,RING_NULL
    }
}
